<layout name='layout/main' />
<header class="am-header am-header-default">
	<div class="am-header-left am-header-nav">
	<a href="<{:U('Store/index')}>"><i class="am-header-icon am-icon-home"></i></a>
    </div>
	<h1 class="am-header-title">商品评论</h1>
</header>

<div class="goodsInfo">

	<div class="goods-base">
		<div class="goods-name"><{$list['name']}><notempty name="list['intr']"><p><{$list['intr']}></p></notempty></div>		
	</div>

	<div class="goods-comment">
		<div class="bd">
			<volist name="comment" id="vo">
			<li>
				<p class="u"><{$vo.wxname}>&nbsp;
				<?php 
				for ($i=0; $i < $vo['star'] ; $i++) { 
					echo '<i class="am-icon-star"></i>';
				}
				?><span><{$vo.createTime|date="Y-m-d",###}></span></p>
				<p><{$vo.content}></p>
				<p class="t">型号：<{$vo.pname}></p>
			</li>
			</volist>
		</div>		
	</div>
</div>


<div class="view-btn">
<?php 
if ($_user['status']) {
?>
	<a href="javascript:void(0)" onclick="addFav(<{$list['id']}>,'<{$list['name']}>','<{$list['price']}>','<{$list['picname']}>')"><i class="am-icon-star-o"></i>收藏</a>	
	<a href="<{:U('Store/cart')}>"><i class="am-icon-shopping-cart"></i>购物车(<span id="cartNum"><{$cartNum}></span>)</a>
<eq name="list.hasoption" value="1">	
	<a href="javascript:void(0)" onclick="buyBtnEvent('add')" class="favBtn">加入购物车</a>
	<a href="javascript:void(0)" onclick="buyBtnEvent('buy')" class="buyBtn">立即购买</a>
<else/>
	<a href="javascript:void(0)" onclick="addCart(<{$list['id']}>)" class="favBtn">加入购物车</a>
	<a href="<{:U('Store/Buy',array('goodsID'=>$list['id']))}>" class="buyBtn">立即购买</a>
</eq>
<?php 
}else{
?>
<div class="am-u-sm-6">
	<button type="button" class="am-btn am-btn-success am-btn-block" onclick="login()"><i class="am-icon-plus"></i> 加入购物车</button>
</div>
<div class="am-u-sm-6">
	<button type="button" class="am-btn am-btn-danger am-btn-block" onclick="login()"><i class="am-icon-cart-plus"></i> 立即购买</button>
</div>
<?php 	
}
?>
</div>


<div class="am-modal am-modal-no-btn" tabindex="-1" id="cartModel">
    <div class="am-modal-dialog" id="btn-response">
      <div class="am-modal-hd">选择商品规格
        <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
      </div>
      <div class="am-modal-bd">
      	<p>价格：<span id="productprice"><{$list['price']}></span></p>
        <div class="goods-pram">
        	<volist name="specs" id="vo">
            <input type='hidden' class='optionid optionid_<{$vo.id}>' value="" title="<{$vo.title}>">
        	<dl <?php if($i==1){echo 'class="fist"';}?>>
            	<dt class="spec_name"><{$vo.title}>:</dt>
                <dd class="spec_items options_<{$vo.id}>" specid="<{$vo.id}>">
                	<volist name="vo.items" id="vo2">
                    	<a class="option option_<{$vo.id}>" href="javascript:;" specid="<{$vo.id}>" oid="<{$vo2.id}>" sel='false'><{$vo2.title}></a>
                    </volist>
                    <div class="clear"></div>
                </dd>
                <dd class="clear"></dd>
            </dl>
            </volist>
        </div>
        <div class="modal-msg"></div>
        <input type="button" id="modal-btn" value="加入购物车" class="am-btn am-btn-block am-btn-danger">
      </div>
    </div>
</div>
<script type="text/javascript">
$(function(){
	$("#modal-btn").click(function(){
		action = $("#action").val();
		goodsID = $("#goodsID").val();
		optionid = $("#optionid").val();

		if(optionid==""){
			alert("请选择规格");
			return false;	
		}

		//操作部分
		if (action=="add"){
			//加入到购物车
			$('#modal-btn').val('操作中...').attr('disabled',"true");
			$.get("index.php?m=Store&a=addcart&goodsID="+goodsID+"&optionid="+optionid+"&temp="+new Date().getTime(),function(response){
				$('#cartModel').modal('close');
				$('#modal-btn').val('加入购物车').removeAttr('disabled',"false");
				_alert(response);
				v = parseInt($('#cartNum span').html())+1;
       			$('#cartNum span').html(v);
			});
		}else if(action=="buy"){
			//跳转到购买
			window.location.href="index.php?m=Store&a=buy&goodsID="+goodsID+"&optionid="+optionid;
		}
	})
})


var _options =<?php  echo json_encode($options); ?>;
var specs =<?php  echo json_encode($specs); ?>;
var hasoption = <?php echo $list['hasoption']=='1'?'true':'false'; ?>;
$(".option").click(function () {
	var specid = $(this).attr("specid");
    var oid = $(this).attr("oid");
    $(".optionid_" + specid).val(oid);
	$(".options_" + specid + " a").removeClass("current").attr("sel", "false");
    $(this).addClass("current").attr("sel", "true");
	var optionid = "";
    var stock = 0;
    var marketprice = 0;
    var productprice = 0;
	var ret = option_selected();
	if (ret.no == '') {
		var len = _options.length;
		for (var i = 0; i < len; i++) {
           var o = _options[i];
		   ret.all = ret.all.sort(function(a,b){
			  return a-b;
		   });
           var ids = ret.all.join("_");
		   var specs=o.specs.split("_");
		   specs = specs.sort(function(a,b){
			  return a-b;
		   });
		   specs = specs.join("_");
           if (specs == ids) {
               optionid = o.id;
               stock = o.stock;
               productprice = o.productprice;
               break;
          }
       }
	   $("#optionid").val(optionid);
       $("#productprice").html(productprice);	
	}
})
function option_selected(){
   var ret= {
       no: "",
       all: []
   };
   if(!hasoption){
       return ret;
   }
   $(".optionid").each(function(){
       ret.all.push($(this).val());
       if($(this).val()==''){
		   ret.no = $(this).attr("title");
           return false;
       }
   });
   return ret;
}
<!--规格选择JS End-->
</script>
<input type="hidden" id="optionid" name="optionid" value=""/>
<input type="hidden" id="goodsID" name="goodsID" value="<{$list['id']}>" />  
<input type="hidden" id="action" name="action" value="" />